/*
 * KendallsTester.java
 *
 * Created on March 26, 2007, 10:39 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package edu.byu.isys413.group1E;
import edu.byu.isys413.group1E.data.*;

/**
 *
 * @author Kendall Frazier
 */
public class RentalTester {
    
    
    /**
     * This is Kendall's Tester.  It tests all his BO's DAO's, and Handlers and all their methods
     *
     * @param args
     */
    public static void main(String args[])  {
        //////////////RSDAO_Factory & RevenueSourceDOA & RevenueSourceBO & RentalDAO & RentalBO///////////////////
        
        //this is commented out while I figure out how the RSDAO_Factory works again
        
        Cache.getAllStackTraces().clear();
        
        RSDAO_Factory factory = RSDAO_Factory.getInstance();
        RevenueSourceDAO revDAO = factory.getDAO("rental");
        RentalBO rentalBO = null;
        ProductDAO prodDAO = ProductDAO.getInstance();
        try{
            rentalBO = (RentalBO)revDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        try{
            rentalBO.setProduct(prodDAO.read("2222011180ff978800000987000002"));
        }catch(Exception e){
            e.printStackTrace();
        }
        
        rentalBO.setDescription("a digital Camera");
        rentalBO.setType("rental");
        rentalBO.setDateOut("2000-03-02");
        rentalBO.setDateDue("2000-03-03");
        rentalBO.setDateIn("2000-03-05") ;
        rentalBO.setPricePerDay(150.00);
                
//         System.out.println("RENTAL: The ID is: " + rentalBO2.getRevSrcID());
//            System.out.println("RENTAL: The description is: " + rentalBO2.getDescription());
//            System.out.println("RENTAL: The Price is: " + rentalBO2.getPrice());
//            System.out.println("RENTAL: the type is: " + rentalBO2.getType());
//            System.out.println("RENTAL: the Product's SKU is: " + rentalBO2.getProduct().getSKU());
//            System.out.println("");
            
        
        ForSaleDAO forSaleDAO = ForSaleDAO.getInstance();
//        try{
//            rentalBO.setProduct(forRentDAO.read("2222011180ff978800000987000002"));
//            
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//        
//        rentalBO.setQuantity(1);
//        
//        try{
//            revDAO.save(rentalBO);
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//        
//        //read from the database
//        SaleBO saleBO2 = null;
//        try{
//            rentalBO2 = (RentalBO)revDAO.read("0000011106b815d50000017f000002");
//            
//            System.out.println("RENTAL: The ID is: " + rentalBO2.getRevSrcID());
//            System.out.println("RENTAL: The description is: " + rentalBO2.getDescription());
//            System.out.println("RENTAL: The Price is: " + rentalBO2.getPrice());
//            System.out.println("RENTAL: the type is: " + rentalBO2.getType());
//            System.out.println("RENTAL: the Product's SKU is: " + rentalBO2.getProduct().getSKU());
//            System.out.println("");
//            
////        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
//        }catch(Exception e){
//            e.printStackTrace();
//        }
        
        
        
        /////////ConceputalDAO&ConceptualBO//////////////////////////////////////////////////////////////
        
        ConceptualDAO conceptualDAO = ConceptualDAO.getInstance();
        ConceptualBO conceptualBO = null;
        try{
            conceptualBO = conceptualDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        conceptualBO.setProductName("Copy Papper");
        conceptualBO.setDescription("good for copying things onto!");
        conceptualBO.setAverageCost(26.50);
        conceptualBO.setPrice(26.00);
        conceptualBO.setProdType("conceptual");
        
        ManufacturerDAO manDAO = ManufacturerDAO.getInstance();
        ManufacturerBO manBO = null;
        try{
            manBO = (ManufacturerBO)manDAO.read("00000110d7f5e9610000007f000322");
        }catch(Exception e){
            e.printStackTrace();
        }
        conceptualBO.setManufacturer(manBO);
        WarrantyDAO warDAO = WarrantyDAO.getInstance();
        WarrantyBO warBO = null;
        try{
            warBO = (WarrantyBO)warDAO.read("19840110d7f5e9610000007f000322");
        }catch(Exception e){
            e.printStackTrace();
        }
        
        conceptualBO.setWarranty(warBO);
//        CategoryDAO catDAO = CategoryDAO.getInstance();
//        CategoryBO catBO = (CategoryBO)catDAO.read("0000011180ff97880000007f000002");
//        conceptualBO.setCategory(catBO);
        
        //sale
        try{
            conceptualDAO.save(conceptualBO);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        //read
        try{
            conceptualBO = (ConceptualBO)conceptualDAO.read("00000111966f99dd000000c0a80164");
            
            System.out.println("CONCEPTUAL: The ProductID is: " + conceptualBO.getProductID());
            System.out.println("CONCEPTUAL: The Product Name is: " + conceptualBO.getProductName());
            System.out.println("CONCEPTUAL: The Description is: " + conceptualBO.getDescription());
            System.out.println("CONCEPTUAL: The AverageCost is: " + conceptualBO.getAverageCost());
            System.out.println("CONCEPTUAL: The Price is: " + conceptualBO.getPrice());
            System.out.println("CONCEPTUAL: The prodType is: " + conceptualBO.getProdType());
            System.out.println("CONCEPTUAL: The SKU is: " + conceptualBO.getSKU());
            System.out.println("CONCEPTUAL: The Manufacturer's ID is: " + conceptualBO.getManufacturer().getId());
            System.out.println("CONCEPTUAL: The Warranty ID is: " + conceptualBO.getWarranty().getId());
            System.out.println("CONCEPTUAL: The SKU is: " + conceptualBO.getSKU());
            
            System.out.println("");
            
//            System.out.println("CONCEPTUAL: The Manufacturer is: "+ conceptualBO.getManufacturer().getID());
//            System.out.println("CONCEPTUAL: The Warranty is: "+ conceptualBO.getWarranty().getID());
//            System.out.println("CONCEPTUAL: The Category is: "+ conceptualBO.getCategory().getID());
            
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
        try{
            conceptualBO = (ConceptualBO)conceptualDAO.readBySKU("C1004");
            
            System.out.println("CONCEPTUAL: The ProductID is: " + conceptualBO.getProductID());
            System.out.println("CONCEPTUAL: The Product Name is: " + conceptualBO.getProductName());
            System.out.println("CONCEPTUAL: The Description is: " + conceptualBO.getDescription());
            System.out.println("CONCEPTUAL: The AverageCost is: " + conceptualBO.getAverageCost());
            System.out.println("CONCEPTUAL: The Price is: " + conceptualBO.getPrice());
            System.out.println("CONCEPTUAL: The prodType is: " + conceptualBO.getProdType());
            System.out.println("CONCEPTUAL: The SKU is: " + conceptualBO.getSKU());
//            System.out.println("CONCEPTUAL: The Category is: "+ conceptualBO.getCategory().getID());
            
            System.out.println("");
            
            
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
        
        
        ///////////ProductDAO & ProductBO & PhysicalDAO & PhysicalBO & ForSaleDAO & ForSaleBO/////////////////
        
        ForSaleBO forSaleBO = null;
        try{
            forSaleBO = forSaleDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        forSaleBO.setDatePurchased("2007-03-15");
        forSaleBO.setNewUsed(true);
        forSaleBO.setPhysType("sale");
        forSaleBO.setPrice(56.95);
        forSaleBO.setShelfLocation("3-b");
        forSaleBO.setSold(false);
        forSaleBO.setProdType("physical");
        forSaleBO.setSKU("P1101");
        forSaleBO.setConceptual(conceptualBO);
        StoreDAO storeDAO = StoreDAO.getInstance();
        StoreBO storeBO = null;
        try{
            storeBO = storeDAO.read("0000011106a3cc220000007f000002");
        }catch(Exception e){
            e.printStackTrace();
        }
        
        forSaleBO.setStore(storeBO);
        
        //save
        try{
            forSaleDAO.save(forSaleBO);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        //read
        try{
            forSaleBO = (ForSaleBO)forSaleDAO.read("0000011180ff97880000017f000002");
            
            System.out.println("FOR SALE: The ProductID is: " + forSaleBO.getProductID());
            System.out.println("FOR SALE: The datePurchased is: " + forSaleBO.getDatePurchased());
            System.out.println("FOR SALE: The newUsed status is: " + forSaleBO.getNewUsed());
            System.out.println("FOR SALE: The PhysType is: " + forSaleBO.getPhysType());
            System.out.println("FOR SALE: The Price is: " + forSaleBO.getPrice());
            System.out.println("FOR SALE: The ShelfLocation is: " + forSaleBO.getShelfLocation());
            System.out.println("FOR SALE: The Sold status is: " + forSaleBO.getSold());
            System.out.println("FOR SALE: The prodType is: " + forSaleBO.getProdType());
            System.out.println("FOR SALE: The SKU is: " + forSaleBO.getSKU());
            System.out.println("FOR SALE: The ConceptualID is: " + forSaleBO.getConceptual().getProductID());
            System.out.println("FOR SALE: The StoreID is: " + forSaleBO.getStore().getStoreID());
            System.out.println("");
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
        try{
            forSaleBO = (ForSaleBO)forSaleDAO.readBySKU("P1001");
            
            System.out.println("FOR SALE: The ProductID is: " + forSaleBO.getProductID());
            System.out.println("FOR SALE: The datePurchased is: " + forSaleBO.getDatePurchased());
            System.out.println("FOR SALE: The newUsed status is: " + forSaleBO.getNewUsed());
            System.out.println("FOR SALE: The PhysType is: " + forSaleBO.getPhysType());
            System.out.println("FOR SALE: The Price is: " + forSaleBO.getPrice());
            System.out.println("FOR SALE: The ShelfLocation is: " + forSaleBO.getShelfLocation());
            System.out.println("FOR SALE: The Sold status is: " + forSaleBO.getSold());
            System.out.println("FOR SALE: The prodType is: " + forSaleBO.getProdType());
            System.out.println("FOR SALE: The SKU is: " + forSaleBO.getSKU());
            System.out.println("FOR SALE: The ConceptualID is: " + forSaleBO.getConceptual().getProductID());
            System.out.println("FOR SALE: The StoreID is: " + forSaleBO.getStore().getStoreID());
            System.out.println("");
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
        
        //////////////Store_Product/////////////////////////////
//
//        StoreProductDAO storeProductDAO = StoreProductDAO.getInstance();
//        StoreProductBO storeProduct = null;
//
//        //it can only create and save it once, because it can't have duplicate keys
//        try{
//            storeProduct = storeProductDAO.create("0000011106a3cc380000007f000002", "00000111966f99dd000000c0a80164");
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//
//        storeProduct.setShelfLocation("2-a");
//        storeProduct.setQtyOnHand(19);
//        storeProduct.setReorderPoint(5);
//        storeProduct.setQtyToOrder(26);
//        storeProduct.setQtyOnOrder(0);
//
//        try{
//            storeProductDAO.save(storeProduct);
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//
//        //read
//        try{
//            storeProduct = (StoreProductBO)storeProductDAO.read("00abcd1106a3cc380000007f000002","00065431966f99dd000000c0a80164");
//
//            System.out.println("STORE_PRODUCT: The storeID is: "+storeProduct.getStoreID());
//            System.out.println("STORE_PRODUCT: The conceptualID is: "+storeProduct.getConceptualID());
//            System.out.println("STORE_PRODUCT: The shelf Location is: "+storeProduct.getShelfLocation());
//            System.out.println("STORE_PRODUCT: The QtyOnHand is: "+storeProduct.getQtyOnHand());
//            System.out.println("STORE_PRODUCT: The ReorderPoint is: "+storeProduct.getReorderPoint());
//            System.out.println("STORE_PRODUCT: The QtyToOrder is: "+storeProduct.getQtyToOrder());
//            System.out.println("STORE_PRODUCT: The QtyOnOrder is: "+storeProduct.getQtyOnOrder());
//            System.out.println("");
//
//
////        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
//        }catch(Exception e){
//            e.printStackTrace();
//        }
        
        ///////////////////////SaleHandler////////////////////////////////////////////////////
        
        SaleHandler saleHandler = SaleHandler.getInstance();
        TransLineBO TXLine = null;
        
        try{
            TXLine = saleHandler.createTXLineWithSale();
        }catch(Exception e){
            e.printStackTrace();
        }
        SaleBO saleBO3 = null;
        
        saleBO3 = (SaleBO)TXLine.getRevSrc();
        try{
            saleBO3 = saleHandler.addProductToSale("P1001", 2);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        System.out.println("HANDLER: quantity is: " + saleBO3.getQuantity());
        System.out.println("HANDLER: price for revLine is: $" + saleBO3.getPrice());
        System.out.println("HANDLER: the description for the sale is: " + saleBO3.getDescription());
        System.out.println("HANDLER: the prodType for the product in the sale is: "+ saleBO3.getProduct().getProdType());
        System.out.println("");
        
        Session session = null;
        EmployeeDAO empDAO = EmployeeDAO.getInstance();
        
        try{
            session = Session.create(empDAO.read("0000011106a3cc390000007f000002"), storeDAO.read("0000011106a3cc380000007f000002"));
        }catch(Exception e){
            e.printStackTrace();
        }
        
        ////////////////Return Handler//////////////////////////////////////
        
        ReturnHandler returnHandler = ReturnHandler.getInstance();
        SaleBO returnSaleBO = null;
        try{
            returnSaleBO = (SaleBO)revDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        try{
            returnSaleBO = returnHandler.MakeReturnRevenueSource("P1001", 5);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        System.out.println("RETURNSALE: The description is: "+returnSaleBO.getDescription());
        System.out.println("RETURNSALE: The price should be negative: "+returnSaleBO.getPrice());
        System.out.println("ReturnSALE: The quantity is: "+returnSaleBO.getQuantity());
        System.out.println("RETURNSALE: The price per unit is: "+returnSaleBO.getProduct().getPrice());
        System.out.println("");
        
        TransactionDAO txDAO = TransactionDAO.getInstance();
        try{
            TransactionBO txBO = txDAO.read("0000011106c0a8ea0000017f000002");
        }catch(Exception e){
            e.printStackTrace();
        }
        
        
        ////////////////////////test classes & Do Batch Processing////////////////////////////////
        PurchaseOrderDAO PODAO = PurchaseOrderDAO.getInstance();
        OrderLineDAO orderLineDAO = OrderLineDAO.getInstance();
        VendorDAO vendDAO = VendorDAO.getInstance();
        VendorItemDAO vItemDAO = VendorItemDAO.getInstance();
        
        
        OrderLineBO OLBO = null;
        try{
            OLBO = orderLineDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        try{
            OLBO.setConceptual((ConceptualBO)conceptualDAO.readBySKU("C1004"));
        }catch(Exception e){
            e.printStackTrace();
        }
        
        OLBO.setLineAmount(350);
        OLBO.setQuantity(10);
        
        try{
            orderLineDAO.save(OLBO);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        //read from the database
        try{
            OLBO = orderLineDAO.read("19840110d12349610360007a000322");
            
            System.out.println("OLBO: The ID is: " + OLBO.getOrderLineID());
            System.out.println("OLBO: The lineAmount is: " + OLBO.getLineAmount());
            System.out.println("OLBO: The Quantity is: " + OLBO.getQuantity());
            System.out.println("OLBO: the description of the product is: " + OLBO.getConceptual().getDescription());
            System.out.println("");
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
        //vendor
        VendorBO vendBO = null;
        try{
            vendBO = vendDAO.create();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        vendBO.setName("Created In the Tester");
        
        try{
            vendDAO.save(vendBO);
        }catch(Exception e){
            e.printStackTrace();
        }
        
        //read from the database
        try{
            vendBO = vendDAO.read("20050110d7f5a9610360007a000322");
            
            System.out.println("Vendor: The ID is: " + vendBO.getVendorID());
            System.out.println("Vendor: The name is: " + vendBO.getName());
            System.out.println("");
            
//        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
        }catch(Exception e){
            e.printStackTrace();
        }
        
//        //vendoitem
//        VendorItemBO vItemBO = null;
//        try{
//            vItemBO = vItemDAO.create("20080110d7f5a9610360007a000322", "00065431966f99dd000000c0a80164");
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//
//        vItemBO.setCost(980);
//
//        try{
//            vItemDAO.save(vItemBO);
//        }catch(Exception e){
//            e.printStackTrace();
//        }
//
//        //read from the database
//        try{
//            vItemBO = vItemDAO.read("20050110d7f5a9610360007a000322", "00000111966f99dd000000c0a80164");
//
//            System.out.println("Vendor_Product: The vendor ID is: " + vItemBO.getVendorID()+ "  the productID is: "+vItemBO.getConceptualID());
//            System.out.println("Vendor_Product: The cost is: " + vItemBO.getCost());
//            System.out.println("");
//
////        System.out.println("the Quantity for the sale is: " + saleBO.getQuantity());
//        }catch(Exception e){
//            e.printStackTrace();
//        }
        
        //////////saleshandler Batch/////////////////////////////////////////////////
        
        SalesBatchHandler batch = SalesBatchHandler.getInstance();
        try{
            batch.PreparePurchaseOrders();
        }catch(Exception e){
            e.printStackTrace();
        }
        
        /////////postSale//////////////////////////////
        
        try{
            saleHandler.postSale(saleBO3, session);
            saleHandler.postSale(returnSaleBO, session);
        }catch(Exception e){
            e.printStackTrace();
        }
        
    }//end main
    
}//end KendallsTester
